package com.aivin.txSms;

import com.aivin.utils.MyStringUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

/**
 * Created by Administrator on 2016/10/21.
 */
public class SmsDemo {

    /**短信验证码的相关配置。使用腾讯云的接口。
     * 地址为https://console.qcloud.com/sms/smslist
     * **/
    public static final int AppID= 1400017189 ;
    public static final String AppKey="db88e41d015b31f67156d32e8cda65ee";


    public static void main(String[] args) {
        testSend();
//        test();

    }


    public static void test (){

        JSONObject jsonObj = JSON.parseObject("fadsfads");
        String errmsg =jsonObj.getString("errmsg") ;
        System.out.println("#######  "+errmsg);

    }


    /****
     * 发送验证码
     */
    public static void testSend(){
        System.out.println(" hello aivin");
        // 开放者实际发送短信时请使用申请的 sdkappid 和 appkey
        SmsSender sender = new SmsSender(AppID, AppKey);
        String msgToUser ="【嘟蜜】123您的验证码是{code}，请于{time}分钟内填写。如非本人操作，请忽略本短信。" ;
        int code= MyStringUtils.getRadomInt( 400000,999999) ;
        int time = 5;
        msgToUser=   msgToUser.replace("{code}" ,String.valueOf(code)).replace("{time}" , String.valueOf(time)) ;

        String userPhone="13650904957" ;
        System.out.println(">>>>>>>  "+userPhone+"  "+msgToUser);
        String resultStr =  sender.sendMsg("86",userPhone, msgToUser);

        System.out.println("#######  "+resultStr);
//        {"result":"0","errmsg":"OK","ext":"","sid":"6:59106110211746266721","count":1,"fee":1}
//        {"result":"1016","errmsg":"error mobile phone number format","ext":""}

        JSONObject jsonObj = JSON.parseObject(resultStr);
        String errmsg =jsonObj.getString("errmsg") ;
        System.out.println("#######  "+errmsg);


    }


}
